package com.ddyx.rest;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.ddyx.service.IStoreService;

@Controller
@RequestMapping("/store")
public class StoreController {
	
	@Resource
	IStoreService storeService;

	/**
	 * 新增门店
	 * @param storeName
	 * @param address
	 * @param location
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "add", method = RequestMethod.POST, consumes = "application/json")
	public @ResponseBody String addStore(@RequestBody JSONObject object){
		return storeService.addStore(object);
	}
	
	/**
	 * 修改门店信息
	 * @param storeId
	 * @param storeName
	 * @param address
	 * @param location
	 * @param phone
	 * @return
	 */
	@RequestMapping(value = "edit", method = RequestMethod.POST, consumes = "application/json")
	public @ResponseBody String editStore(@RequestBody JSONObject object){
		return storeService.editStore(object);			
	}
	
	@RequestMapping(params = "cmd=listStore", method = RequestMethod.GET)
	public @ResponseBody String selectByStoreName(@RequestParam(value="page",defaultValue="1") int page
			,@RequestParam(value="size",defaultValue="20") int size
			,@RequestParam(value="storeName",defaultValue="")String storeName
			,@RequestParam(value="storeNo",defaultValue="")String storeNo) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("page", page);
		map.put("size", size);
		map.put("storeName", storeName);
		map.put("storeNo", storeNo);
		return storeService.selectStoreByName(map);
	}
}
